package com.cleaningcloud.cld.controller;

import com.cleaningcloud.cld.domain.CldPayConfirm;
import com.cleaningcloud.cld.domain.dto.CldPayConfirmDto;
import com.cleaningcloud.cld.domain.excelExport.SalaryExcelExport;
import com.cleaningcloud.cld.service.ICldPayConfirmService;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 薪酬确认Controller
 *
 * @author cleaningcloud
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/confirm")
public class CldPayConfirmController extends BaseController {
    @Autowired
    private ICldPayConfirmService cldPayConfirmService;

    /**
     * 查询薪酬确认列表
     */
    @RequiresPermissions("cld:confirm:list")
    @GetMapping("/list")
    public TableDataInfo list(CldPayConfirm cldPayConfirm) {
        startPage();
        List<CldPayConfirm> list = cldPayConfirmService.selectCldPayConfirmList(cldPayConfirm);
        return getDataTable(list);
    }

    /**
     * 导出薪酬确认列表
     */
    @Log(title = "薪酬确认", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalaryExcelExport salaryExcelExport) {
        List<SalaryExcelExport> list = cldPayConfirmService.selectSalaryExcelExport(salaryExcelExport);
        ExcelUtil<SalaryExcelExport> util = new ExcelUtil<SalaryExcelExport>(SalaryExcelExport.class);
        util.exportExcel(response, list, "薪酬确认数据");
    }

    /**
     * 获取薪酬确认详细信息
     */
    @RequiresPermissions("cld:confirm:query")
    @GetMapping(value = "/{payConfirmId}")
    public AjaxResult getInfo(@PathVariable("payConfirmId") Long payConfirmId) {
        return success(cldPayConfirmService.selectCldPayConfirmByPayConfirmId(payConfirmId));
    }

    /**
     * 新增薪酬确认
     */
    @RequiresPermissions("cld:confirm:add")
    @Log(title = "薪酬确认", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldPayConfirm cldPayConfirm) {
        return toAjax(cldPayConfirmService.insertCldPayConfirm(cldPayConfirm));
    }

    /**
     * 修改薪酬确认
     */
    @RequiresPermissions("cld:confirm:edit")
    @Log(title = "薪酬确认", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldPayConfirm cldPayConfirm) {
        return toAjax(cldPayConfirmService.updateCldPayConfirm(cldPayConfirm));
    }

    /**
     * 删除薪酬确认
     */
    @RequiresPermissions("cld:confirm:remove")
    @Log(title = "薪酬确认", businessType = BusinessType.DELETE)
    @DeleteMapping("/{payConfirmIds}")
    public AjaxResult remove(@PathVariable Long[] payConfirmIds) {
        return toAjax(cldPayConfirmService.deleteCldPayConfirmByPayConfirmIds(payConfirmIds));
    }


    /**
     * 修改薪酬确认
     */
    @RequiresPermissions("cld:confirm:confirmIssuance")
    @Log(title = "薪酬发放", businessType = BusinessType.UPDATE)
    @PutMapping("/confirmIssuance")
    public AjaxResult confirmIssuance(@RequestBody CldPayConfirmDto cldPayConfirm) {
        return toAjax(cldPayConfirmService.confirmIssuance(cldPayConfirm));
    }
}
